#include "hdu_parser.h"

std::string HduParser::operator() (const char *user_id) {
	const char *parser_module = "hdu_py_parser";
	const char *parser_func   = "get_status";
	const char *stream;

	PyObject *parser = PyImport_ImportModule( parser_module );
	if (!parser) {
		puts("PyImport_ImportModule failed");
		return 0;
	}

	// 调用这个函数，这个函数是需要参数的，也有返回值	
	PyObject *get_status = PyObject_GetAttrString(parser, parser_func);
	if (!get_status) {
		puts("PyObject_GetAttrString 'get_status' failed");
		return 0;
	}

	// 设置参数
	PyObject *arg = Py_BuildValue("(s)", user_id);
	PyObject *result = PyEval_CallObject(get_status, arg);	
	// 解析返回值
	PyArg_Parse(result, "s", &stream);
		
	std::string stream_(stream);
	//delete parser;
	//delete get_status;
	//delete arg;
	//delete result;
	return stream_;
}


